package com.jcl.recruit.log.mapper;

import com.jcl.recruit.log.model.ResumeLog;
import com.jcl.recruit.mapper.SqlMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


public interface ResumeLogMapper extends SqlMapper {

    @Select({
            "select a.*,b.realname from resume_log a " +
                    "left join user b on a.user_id = b.id " +
                    "where resume_id = #{resumeId} order by createtime desc "
    })
    List<ResumeLog> findList(@Param("resumeId") Integer resumeId);

    @Select({
            "<script>",
            "select * from resume_log",
            "<where>",
            "<if test=\"null!=corpCode\">",
            "and corp_code = #{corpCode}",
            "</if>",
            "<if test=\"null!=userId\">",
            "and user_id = #{userId}",
            "</if>",
            "<if test=\"null!=category\">",
            "and category = #{category}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<ResumeLog> findListByCorp(@Param("corpCode") String corpCode,
                                   @Param("userId") Integer userId,
                                   @Param("category") Integer category);

    @Select({
            "select a.*,b.realname from resume_log a left join user b on a.user_id = b.id where resume_id = #{resumeId} order by createtime desc "
    })
    List<Map<String,Object>> selectResumeLogsByResumeId(@Param("resumeId") Integer resumeId);

    @Select({
            QUERY_SCRIPT_START,
            "select user_id as userId, count(*) as number from resume_log ",
            QUERY_WHERE_START,
            IF_START_USER_IDS,
            SQL_PROPERTY_USER_ID,SQL_IN,
            FOREACH_START_LIST_USER_IDS, SQL_PROPERTY_USER_ID_VALUE, FOREACH_END,
            IF_END,
            "<if test='null!=category'>",
            SQL_AND," category = #{category} ",
            IF_END,
            QUERY_WHERE_END,
            " GROUP BY userId ",
            QUERY_SCRIPT_END
    })
    List<Map<String,Object>> findCountResumeByUsers(@Param("userIds") List<Integer> userIds,
                                                    @Param("category") Integer category);


    @InsertProvider(type = ResumeLogProvider.class, method = "insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(ResumeLog record);
}
